﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace lumo.display.object2D
{
    /// <summary>
    /// A Simple 2D text class on the screen.
    /// </summary>
    public class Label : IObject2D, IColorable, IPositionable2D, IOriginable2D, IRotationable2D, IMirrorable2D, IScalable2D
    {

    #region Instance

        /// <summary> 
        /// Text of the label.
        /// </summary>
        public string Text = null;
        /// <summary> 
        /// Font of the label.
        /// </summary>
        public SpriteFont SpriteFont = null;

        /// <summary>
        /// Label empty constructor.
        /// </summary>
        public Label() {}

        /// <summary>
        /// Label constructor from an sprite font and a text.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="spriteFont">The sprite font</param>
        public Label(string text, SpriteFont spriteFont)
        {
            Text = text;
            SpriteFont = spriteFont;
        }

    #endregion

    #region Interface Implementations

        #region IObject2D

        /// <summary>
        /// Draw implementaion of IObject2D
        /// </summary>
        /// <param name="spriteBatch"></param>
        public void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
            if (_Visible && (Text != null) && (SpriteFont != null))
                spriteBatch.DrawString(SpriteFont, Text, _Position, _Color, _Radians, _Origin, _Scale, _SpriteEffects, 0f);
        }

        /// <summary>Private draw order float.</summary>
        private float _DrawOrder = 0f;
        /// <summary>
        /// Simple implementation of draw order.
        /// </summary>
        public float DrawOrder { get { return _DrawOrder; } set { _DrawOrder = value; } }

        /// <summary>Private visible variable.</summary>
        private bool _Visible = true;        /// <summary>
        /// Simple implementation of Visible.
        /// </summary>
        public bool Visible { get { return _Visible; } set { _Visible = value; } }

        #endregion

        #region IColorable

        /// <summary> 
        /// Colormask 
        /// </summary>
        private Color _Color = Color.White;
        /// <summary>
        /// Implemetaion of Color. IColorable
        /// </summary>
        public Color Color { get { return _Color; } set { _Color = value; } }
        /// <summary>
        /// Implemetaion of ColorR. IColorable
        /// </summary>
        public byte ColorR { get { return _Color.R; } set { _Color.R = value; } }
        /// <summary>
        /// Implemetaion of ColorG. IColorable
        /// </summary>
        public byte ColorG { get { return _Color.G; } set { _Color.G = value; } }
        /// <summary>
        /// Implemetaion of ColorB. IColorable
        /// </summary>
        public byte ColorB { get { return _Color.B; } set { _Color.B = value; } }
        /// <summary>
        /// Implemetaion of ColorA. IColorable
        /// </summary>
        public byte ColorA { get { return _Color.A; } set { _Color.A = value; } }

        #endregion

        #region IPositionable2D

        /// <summary> 
        /// Coordinates where the object is drawn 
        /// </summary>
        private Vector2 _Position = Vector2.Zero;
        /// <summary>
        /// Implementation of Position. IPositionable2D.
        /// </summary>
        public Vector2 Position { get { return _Position; } set { _Position = value; } }
        /// <summary>
        /// Implementation of X. IPositionable2D.
        /// </summary>
        public float X { get { return _Position.X; } set { _Position.X = value; } }
        /// <summary>
        /// Implementation of Y. IPositionable2D.
        /// </summary>
        public float Y { get { return _Position.Y; } set { _Position.Y = value; } }

        #endregion

        #region IOriginable2D

        /// <summary>
        /// Size of obejct.
        /// </summary>
        public Vector2 Size { get { if ((Text != null) && (SpriteFont != null)) return SpriteFont.MeasureString(Text); return Vector2.Zero; } }
        /// <summary> 
        /// Pivot point 
        /// </summary>
        private Vector2 _Origin = Vector2.Zero;
        /// <summary>
        /// Implemetation of Origin. IOriginable2D.
        /// </summary>
        public Vector2 Origin { get { return _Origin; } set { _Origin = value; } }
        /// <summary>
        /// Implementation of OX. IOriginable2D.
        /// </summary>
        public float OX { get { return _Origin.X; } set { _Origin.X = value; } }
        /// <summary>
        /// Implementation of OY. IOriginable2D.
        /// </summary>
        public float OY { get { return _Origin.Y; } set { _Origin.Y = value; } }

        #endregion

        #region IRotationable2D

        /// <summary> 
        /// Angle in radians 
        /// </summary>
        private float _Radians = 0f;
        /// <summary>
        /// Implementation of Radians. IRotationable2D
        /// </summary>
        public float Radians { get { return _Radians; } set { _Radians = value; } }
        /// <summary>
        /// Implementation of Degrees. IRotationable2D
        /// </summary>
        public float Degrees { get { return MathHelper.ToDegrees(_Radians); } set { _Radians = MathHelper.ToRadians(value); } }

        #endregion

        #region IMirrorable2D

        /// <summary>
        /// Mirroring option
        /// </summary>
        private SpriteEffects _SpriteEffects = SpriteEffects.None;

        /// <summary>
        /// Implementation of mirroring option. IMirrorable2D
        /// </summary>
        public SpriteEffects SpriteEffects { get { return _SpriteEffects; } set { _SpriteEffects = value; } }

        #endregion

        #region IScalable2D

        /// <summary> 
        /// Zoom 
        /// </summary>
        private Vector2 _Scale = Vector2.One;
        /// <summary>
        /// Implementation of Scale. IScalable2D.
        /// </summary>
        public Vector2 Scale { get { return _Scale; } set { _Scale = value; } }
        /// <summary>
        /// Implementation of ScaleX. IScalable2D.
        /// </summary>
        public float ScaleX { get { return _Scale.X; } set { _Scale.X = value; } }
        /// <summary>
        /// Implementation of ScaleY. IScalable2D.
        /// </summary>
        public float ScaleY { get { return _Scale.Y; } set { _Scale.Y = value; } }

        #endregion

    #endregion

    }
}
